// -*- C++ -*-
-// $Id: upgrade.cpp,v 1.6 2009/08/07 00:25:43 robertl Exp $
+// $Id: upgrade.cpp,v 1.7 2009/08/09 03:09:11 robertl Exp $
/*
Copyright (C) 2009 Robert Lipe, robertlipe@gpsbabel.org
#include <QHttp>
#include <QMessageBox>
+#include <QDesktopServices>
#include <QDomDocument>
#include <QSysInfo>
+#include <QUrl>
// static const bool testing = true;
static const bool testing = false;
-static int versionAsNumber(const QString &s)
-{
- QStringList list = s.split(".");
- return (list[0].toInt()<<16 | list[1].toInt() << 8 | list[2].toInt() );
-}
-
UpgradeCheck::UpgradeCheck(QWidget *parent) :
QObject(parent),
http(0)
}
}
-// See http://doc.trolltech.com/4.5/qsysinfo.html to interpret results
QString UpgradeCheck::UpgradeCheck::getOsName(void)
{
- // Do not translate these strings.
+ // Do not translate these strings.
#if defined (Q_OS_LINUX)
- return "Linux";
+ return "Linux";
#elif defined (Q_OS_MAC)
- return QString("Mac %1").arg(QSysInfo::MacintoshVersion);
+ return "Mac";
#elif defined (Q_OS_WIN)
- return QString("Windows %1").arg(QSysInfo::WindowsVersion);
+ return "Windows";
#elif
- return "Unknown"'
+ return "Unknown"'
#endif
-
+
}
-UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString ¤tVersion,
- int checkMethod,
- const QDateTime &lastCheckTime,
- const QString &installationUuid)
+// See http://doc.trolltech.com/4.5/qsysinfo.html to interpret results
+QString UpgradeCheck::UpgradeCheck::getOsVersion(void)
{
- this->currentVersion = currentVersion;
+ #if defined (Q_OS_MAC)
+ switch (QSysInfo::MacintoshVersion) {
+ case QSysInfo::MV_10_3: return "10.3"; break;
+ case QSysInfo::MV_10_4: return "10.4"; break;
+ case QSysInfo::MV_10_5: return "10.5"; break;
+ case QSysInfo::MV_10_6: return "10.6"; break;
+ default: return QString("Unknown Mac %1").arg(QSysInfo::MacintoshVersion);
+ };
+ #elif defined (Q_OS_WIN)
+ switch (QSysInfo::WinVersion) {
+ // Wildly improbable...
+ case QSysInfo::WV_95: return "95"; break;
+ case QSysInfo::WV_98: return "98"; break;
+ case QSysInfo::WV_Me: return "Me"; break;
+
+ case QSysInfo::WV_4_0: return "NT 4"; break;
+ case QSysInfo::WV_5_0: return "2000"; break;
+ case QSysInfo::WV_5_1: return "XP"; break;
+ case QSysInfo::WV_5_2: return "2003"; break;
+ case QSysInfo::WV_6_0: return "Vista"; break;
+ case QSysInfo::WV_6_1: return "7"; break;
+
+ }
+ #endif
+ // FIXME: find something appropriately clever to do for Linux, etc. here.
+ return "Unknown";
+}
+
+
+UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString ¤tVersionIn,
+ int checkMethod,
+ const QDateTime &lastCheckTime,
+ const QString &installationUuid)
+{
+ this->currentVersion = currentVersionIn;
+ this->currentVersion.remove("GPSBabel Version");
this->upgradeCheckMethod = checkMethod;
QDateTime soonestCheckTime = lastCheckTime.addDays(1);
// Not time to check yet.
return UpgradeCheck::updateUnknown;
}
-
+
http = new QHttp;
connect(http, SIGNAL(requestFinished(int, bool)),
header.setValue("Host", "www.gpsbabel.org");
QString args = "current_version=" + currentVersion;
- args += "&installation=" + installationUuid;
- args += "&os=" + getOsName();
+ args += "&installation=" + installationUuid;
+ args += "&os=" + getOsName();
+ args += "&os_ver=" + getOsVersion();
+ args += "&beta_ok=1"; // Eventually to come from prefs.
http->setHost("www.gpsbabel.org");
- httpRequestId = http->request(header, args.toUtf8());
+ httpRequestId = http->request(header, args.toUtf8());
return UpgradeCheck::updateUnknown;
}
default:
QMessageBox::information(0, tr("HTTP"),
- tr("Download failed: %1.")
- .arg(responseHeader.reasonPhrase()));
+ tr("Download failed: %1.")
+ .arg(responseHeader.reasonPhrase()));
httpRequestAborted = true;
http->abort();
}
return;
QString response;
+ QString upgradeText;
if (testing)
currentVersion = "1.3.1"; // for testing
bool allowBeta = false; // TODO: come from prefs or current version...
- int currentVersionNum = versionAsNumber(currentVersion);
-
QDomNodeList upgrades = document.elementsByTagName("update");
for (unsigned int i = 0; i < upgrades.length(); i++) {
bool updateIsBeta = upgrade.attribute("type") == "beta";
bool updateIsMajor = upgrade.attribute("type") == "major";
bool updateCandidate = updateIsMajor || (updateIsBeta && allowBeta);
- int updateVersionNum = versionAsNumber(updateVersion);
-
- if(updateVersionNum > currentVersionNum && updateCandidate) {
- response = tr("<center><b>A new version of GPSBabel is available</b><br>"
- "Your version is %1 <br>"
- "The latest version is %2</center>"
- "<center><a ref=\"http://www.gpsbabel.org/download.html\">"
- "Download GPSBabel</a> now.</center>")
- .arg(currentVersion)
- .arg(updateVersion);
-
+ upgradeText = upgrade.firstChildElement("overview").text();
+
+ // String compare, not a numeric one. Server will return "best first".
+ if((updateVersion > currentVersion) && updateCandidate) {
+ response = tr("A new version of GPSBabel is available.<br />"
+ "Your version is %1 <br />"
+ "The latest version is %2")
+ .arg(currentVersion)
+ .arg(updateVersion);
break;
}
}
-
+
if (response.length()) {
QMessageBox information;
information.setWindowTitle(tr("Upgrade"));
- information.setTextFormat(Qt::RichText);
+
+ information.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ information.setDefaultButton(QMessageBox::Yes);
+
information.setText(response);
- information.exec();
+ information.setInformativeText(tr("Do you wish do download an upgrade?"));
+ information.setDetailedText(upgradeText);
+
+ switch (information.exec()) {
+ case QMessageBox::Yes:
+ QDesktopServices::openUrl(QUrl("http://www.gpsbabel.org/download.html", QUrl::TolerantMode));
+ default: ;
+ }
+
upgradeWarningTime = QDateTime(QDateTime::currentDateTime());
}
-
+
delete http;
http = 0;
}